package com.yiba.vpn.protocal;

import com.yiba.vpn.utils.BufferUtil;

import java.nio.ByteBuffer;

/**
 * Created by Administrator on 2017/11/16 0016.
 */

public class DBQPacket {
    public DBQHeader Header = new DBQHeader();
    public int Size = 8;
    public String data = "";

    public static DBQPacket fromBytes(ByteBuffer buffer) {
        if (buffer.limit() < 8) {
            return null;
        }
        DBQPacket packet = new DBQPacket();
        packet.Size = buffer.limit();
        packet.Header = DBQHeader.fromBytes(buffer);
        buffer.position(8);
        packet.data = BufferUtil.getString(buffer);
        return packet;
    }

    public void toBytes(ByteBuffer buffer) {
        this.Header.toBytes(buffer);
        buffer.put(this.data.getBytes());
    }

}
